﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Zongcaozuo : MonoBehaviour
{
    // 导入横方块
    public GameObject[] Fangkuai;
    // 创建横列方块
    public GameObject[,] ZongFangkuai;
    // 游戏中的方块模型
    public GameObject CreateCube;
    // 游戏中的得分
    public Text GameText;
    private int GametextNum = 0;
    // 游戏进行指令 第一条许可
    public bool FirstXK = false, SecondXK=false,ThirdXK=false,FourthXK=false,FirthXK=false;

    // 游戏中显示玩家操控方块
    private int[,] Hanglie;

    // 将下一个显示的方块导入
    public GameObject[] LsFangkuai;

    // 游戏结束字显示
    public Text ExitMessage;

    // 存储方块编号
    private int Qs3 = 0,Qs4=0;
    
    // 方块变形编号
    private int Qs3Bianxing = 1;

    // 方块消除准备行数
    private int FKXH = 0;

    // 方块消除已消除行数
    private int FKXH1 = 0;




    void Start()
    {
        // 可移动方块坐标起始为-1
        Hanglie = new int[6,2];
        for (int i = 0; i < Hanglie.GetLength(0); i++)
        {
            for (int j = 0; j < Hanglie.GetLength(1); j++)
                Hanglie[i, j] = -1;
        }

            // 下一个显示方块导入
            LsFangkuai = new GameObject[6];
        for (int i = 0; i < LsFangkuai.Length; i++)
            if (LsFangkuai[i] == null)
                LsFangkuai[i] = GameObject.Find("Shili0" + (i + 1));


        // 初始化方块行数
        Fangkuai = new GameObject[22];
        for (int i = 0; i < Fangkuai.Length; i++)
        {
            if (Fangkuai[i] == null)
            {
                Fangkuai[i] = GameObject.Find((i + 1) + "hang");
            }
        }

        // 初始化方块行列数
        ZongFangkuai = new GameObject[22, 15];
        for (int i = 0; i < ZongFangkuai.GetLength(0); i++)
            for (int j = 0; j < ZongFangkuai.GetLength(1); j++)
            {
                ZongFangkuai[i, j] = Fangkuai[i].transform.GetChild(j).gameObject;
            }


        // 初始化一次"下一次方块"
        int Qs = Random.Range(1, 9);
        Qs3 = Qs;
        LSTetris(Qs);



    }


    void Update()
    {
        // 第一步  复制"下一个"栏中的方块
        if (FirstXK)
        {
            // 玩家可移动方块初始化
            for (int i = 0; i < Hanglie.GetLength(0); i++)
            {
                for (int j = 0; j < Hanglie.GetLength(1); j++)
                    Hanglie[i, j] = -1;
            }

            // 复制方块
            for (int i = 0; i < LsFangkuai.Length; i++){
                int K = 21, S = 6;
                if(i>=3)
                    K=20;
                if (S + i > 8)
                    S -= 3;
                if (LsFangkuai[i].transform.GetChildCount() == 1)
                {
                    GameObject tempa = LsFangkuai[i].transform.GetChild(0).gameObject;
                    tempa.transform.parent = ZongFangkuai[K, S + i].transform;
                    tempa.transform.position = ZongFangkuai[K, S + i].transform.position;

                    // 坐标记录
                    Hanglie[i, 0] = K;
                    Hanglie[i, 1] = S + i;
                }
            }
            // 第一步取消
            FirstXK = false;
            // 第二步开启
            SecondXK = true;
            // 第三步开启
            ThirdXK = true;
        }

        // 第二步  制作"下一个"栏中的方块
        if (SecondXK)
        {
            // 初始化下一个方块格子
            LSReset();

            Qs4 = Random.Range(1, 9);

            // 识别随机数 创建"下一个"区域俄罗斯方块
            LSTetris(Qs4);

            SecondXK = false;

        }

        // 第三步  下降允许 与第二步同步运行
        if (ThirdXK)
        {
            Invoke("DownMove",1f);
            ThirdXK = false;
 
        }

        // 第四步 第三步的后续,砖块的停留,将tag变更,回归first
        if (FourthXK)
        {
            StayCube();
            Xiaohang();
        }
        else if (FirthXK)   // 第五步 消除后 将上方方块下移动 ,但与第四步互斥
        {
            FKXiajiang();
 
        }


        // 这里考虑的是左移或右移了
        if (Input.GetKeyUp(KeyCode.LeftArrow))
        {
            LeftMove();
        }

        if (Input.GetKeyUp(KeyCode.RightArrow))
        {
            RightMove();
        }

        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            DownACMove();
        }


        if (Input.GetKeyUp(KeyCode.UpArrow))
        {
            Bianxing();
        }

        if (Input.GetKeyUp(KeyCode.Space))
        {
            DownInstandMove();
        }

    }



    // 重置下一个显示的区域
    void LSReset()
    {
        for(int i=0;i<LsFangkuai.Length;i++)
            if (LsFangkuai[i].transform.GetChildCount() != 0)
            {
                Destroy(LsFangkuai[i].transform.GetChild(0).gameObject);
            }

    }

    // "下一个"区域俄罗斯方块
    void LSTetris(int Qs)
    {   // Qs等于1时 只有一个方块
        if (Qs == 1)
        {

            GameObject s = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
            s.transform.parent = LsFangkuai[4].transform;
            s.transform.position = LsFangkuai[4].transform.position;
        }
        else
            if (Qs == 2)  // 三个方块
            {
                GameObject s1 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                s1.transform.parent = LsFangkuai[3].transform;
                s1.transform.position = LsFangkuai[3].transform.position;

                GameObject s2 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                s2.transform.parent = LsFangkuai[4].transform;
                s2.transform.position = LsFangkuai[4].transform.position;

                GameObject s3 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                s3.transform.parent = LsFangkuai[5].transform;
                s3.transform.position = LsFangkuai[5].transform.position;
            }
            else
                if (Qs == 3)  // 四个方块
                {
                    GameObject s1 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                    s1.transform.parent = LsFangkuai[0].transform;
                    s1.transform.position = LsFangkuai[0].transform.position;

                    GameObject s2 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                    s2.transform.parent = LsFangkuai[1].transform;
                    s2.transform.position = LsFangkuai[1].transform.position;

                    GameObject s3 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                    s3.transform.parent = LsFangkuai[4].transform;
                    s3.transform.position = LsFangkuai[4].transform.position;

                    GameObject s4 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                    s4.transform.parent = LsFangkuai[5].transform;
                    s4.transform.position = LsFangkuai[5].transform.position;
                }
                else
                    if (Qs == 4)  // 四个方块
                    {
                        GameObject s1 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                        s1.transform.parent = LsFangkuai[0].transform;
                        s1.transform.position = LsFangkuai[0].transform.position;

                        GameObject s2 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                        s2.transform.parent = LsFangkuai[1].transform;
                        s2.transform.position = LsFangkuai[1].transform.position;

                        GameObject s3 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                        s3.transform.parent = LsFangkuai[3].transform;
                        s3.transform.position = LsFangkuai[3].transform.position;

                        GameObject s4 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                        s4.transform.parent = LsFangkuai[4].transform;
                        s4.transform.position = LsFangkuai[4].transform.position;
                    }
                    else
                        if (Qs == 5)  // 四个方块 右拐
                        {
                            GameObject s1 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                            s1.transform.parent = LsFangkuai[2].transform;
                            s1.transform.position = LsFangkuai[2].transform.position;

                            GameObject s2 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                            s2.transform.parent = LsFangkuai[3].transform;
                            s2.transform.position = LsFangkuai[3].transform.position;

                            GameObject s3 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                            s3.transform.parent = LsFangkuai[4].transform;
                            s3.transform.position = LsFangkuai[4].transform.position;

                            GameObject s4 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                            s4.transform.parent = LsFangkuai[5].transform;
                            s4.transform.position = LsFangkuai[5].transform.position;
                        }
                        else
                            if (Qs == 6)  // 四个方块 左拐
                            {
                                GameObject s1 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                s1.transform.parent = LsFangkuai[0].transform;
                                s1.transform.position = LsFangkuai[0].transform.position;

                                GameObject s2 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                s2.transform.parent = LsFangkuai[3].transform;
                                s2.transform.position = LsFangkuai[3].transform.position;

                                GameObject s3 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                s3.transform.parent = LsFangkuai[4].transform;
                                s3.transform.position = LsFangkuai[4].transform.position;

                                GameObject s4 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                s4.transform.parent = LsFangkuai[5].transform;
                                s4.transform.position = LsFangkuai[5].transform.position;
                            }
                            else
                                if (Qs == 7)  // 四个方块 凸状
                                {
                                    GameObject s1 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                    s1.transform.parent = LsFangkuai[1].transform;
                                    s1.transform.position = LsFangkuai[1].transform.position;

                                    GameObject s2 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                    s2.transform.parent = LsFangkuai[3].transform;
                                    s2.transform.position = LsFangkuai[3].transform.position;

                                    GameObject s3 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                    s3.transform.parent = LsFangkuai[4].transform;
                                    s3.transform.position = LsFangkuai[4].transform.position;

                                    GameObject s4 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                    s4.transform.parent = LsFangkuai[5].transform;
                                    s4.transform.position = LsFangkuai[5].transform.position;
                                }
                                else
                                    if (Qs == 8)  // 四个方块 3的反方向
                                    {
                                        GameObject s1 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                        s1.transform.parent = LsFangkuai[2].transform;
                                        s1.transform.position = LsFangkuai[2].transform.position;

                                        GameObject s2 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                        s2.transform.parent = LsFangkuai[1].transform;
                                        s2.transform.position = LsFangkuai[1].transform.position;

                                        GameObject s3 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                        s3.transform.parent = LsFangkuai[4].transform;
                                        s3.transform.position = LsFangkuai[4].transform.position;

                                        GameObject s4 = Instantiate(CreateCube, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
                                        s4.transform.parent = LsFangkuai[3].transform;
                                        s4.transform.position = LsFangkuai[3].transform.position;
                                    }
    }

    // 砖块自动下移
    void DownMove()
    {
 
            bool Down = false;
            int Counts1 = 0, Counts2 = 0;
            // 取数量
            for (int i = 0; i < Hanglie.GetLength(0); i++)
                if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
                {
                    Counts1++;
                    if (Hanglie[i, 0] - 1 >= 0)
                    {
                        if (ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].CompareTag("Stop") == false)
                            Counts2++;
                        if (ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].transform.GetChildCount() != 0)
                            if (ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].transform.GetChild(0).CompareTag("Stop") == true)
                            {
                                Counts2--;

                            }
                    }
                }

            // 如果该位置的坐标不等于-1 那么存在方块
            for (int i = 0; i < Hanglie.GetLength(0); i++)
                if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
                {
                    // Hanglie[,] 代表的数字为 行列
                    GameObject temp = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1]].transform.GetChild(0).gameObject;
                    // 最底层 或如果底下无child
                    if (Counts1 == Counts2)
                    {
                        temp.transform.parent = ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].transform;
                        temp.transform.position = ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].transform.position;

                        Hanglie[i, 0] -= 1;
                    }

                }

            // 如果不相等,说明应该停留砖块.
            if (Counts1 == Counts2)
                ThirdXK = true;
            else
            {
                ThirdXK = false;
                FourthXK = true;
            }





    }

    // 方块停留处理
    void StayCube()
    {
        for (int i = 0; i < Hanglie.GetLength(0); i++)
            if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
            {
            GameObject temp = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1]].transform.GetChild(0).gameObject;
            temp.tag = "Stop";
        }
        FourthXK = false;
        FirstXK = true;   // 第一步开启
        Qs3 = Qs4;
        Qs3Bianxing = 1;

        PlayerExit();
    }

    // 检测玩家失败
    void PlayerExit()
    {
        for (int i = ZongFangkuai.GetLength(0) - 2; i < ZongFangkuai.GetLength(0); i++)
            for (int j = 0; j < ZongFangkuai.GetLength(1);j++ )
            {
               
                if (ZongFangkuai[i, j].transform.GetChildCount() != 0)
                    if (ZongFangkuai[i, j].transform.GetChild(0).tag.CompareTo("Stop")==0)
                    {
                    ExitMessage.gameObject.SetActive(true);
                    FirstXK = false;
                }
            }
    }


    // 砖块左移动
    void LeftMove()
    {
 

            int Counts1 = 0, Counts2 = 0;
            // 取数量
            for (int i = 0; i < Hanglie.GetLength(0); i++)
                if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
                {
                    Counts1++;
                    if (Hanglie[i, 1] - 1 >= 0)
                    {
                        if (ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1] - 1].CompareTag("Stop") == false)
                            Counts2++;
                        if (ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1] - 1].transform.GetChildCount() != 0)
                            if (ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1] - 1].transform.GetChild(0).CompareTag("Stop") == true)
                            {
                                Counts2--;

                            }
                    }
                }

            for (int i = 0; i < Hanglie.GetLength(0); i++)
            {
                if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
                {
                    GameObject temp1 = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1]].transform.GetChild(0).gameObject;
                    if (Counts1 == Counts2)
                    {
                        temp1.transform.parent = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1]-1].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1]-1].transform.position;

                        Hanglie[i, 1] -= 1;

                    }
                }
            }
    }

    // 砖块右移动
    void RightMove()
    {


        int Counts1 = 0, Counts2 = 0;
        // 取数量
        for (int i = 0; i < Hanglie.GetLength(0); i++)
            if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
            {
                Counts1++;
                if (Hanglie[i, 1] + 1 <ZongFangkuai.GetLength(1))
                {
                    if (ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1] + 1].CompareTag("Stop") == false)
                        Counts2++;
                    if (ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1] + 1].transform.GetChildCount() != 0)
                        if (ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1] + 1].transform.GetChild(0).CompareTag("Stop") == true)
                        {
                            Counts2--;

                        }
                }
            }

        for (int i = 0; i < Hanglie.GetLength(0); i++)
        {
            if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
            {
                GameObject temp1 = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1]].transform.GetChild(0).gameObject;
                if (Counts1 == Counts2)
                {
                    temp1.transform.parent = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1] + 1].transform;
                    temp1.transform.position = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1] + 1].transform.position;

                    Hanglie[i, 1] += 1;

                }
            }
        }
    }

    // 砖块下移动加速
    void DownACMove()
    {


        int Counts1 = 0, Counts2 = 0;
        // 取数量
        for (int i = 0; i < Hanglie.GetLength(0); i++)
            if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
            {
                Counts1++;
                if (Hanglie[i, 0] - 1 >= 0)
                {
                    if (ZongFangkuai[Hanglie[i, 0] -1, Hanglie[i, 1] ].CompareTag("Stop") == false)
                        Counts2++;
                    if (ZongFangkuai[Hanglie[i, 0] -1, Hanglie[i, 1] ].transform.GetChildCount() != 0)
                        if (ZongFangkuai[Hanglie[i, 0] -1, Hanglie[i, 1] ].transform.GetChild(0).CompareTag("Stop") == true)
                        {
                            Counts2--;
                        }
                }
            }

        for (int i = 0; i < Hanglie.GetLength(0); i++)
        {
            if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
            {
                GameObject temp1 = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1]].transform.GetChild(0).gameObject;
                if (Counts1 == Counts2)
                {
                    temp1.transform.parent = ZongFangkuai[Hanglie[i, 0] -1, Hanglie[i, 1] ].transform;
                    temp1.transform.position = ZongFangkuai[Hanglie[i, 0] -1, Hanglie[i, 1] ].transform.position;

                    Hanglie[i, 0] -=1;

                }
            }
        }
    }

    // 砖块瞬间下降
    void DownInstandMove()
    {
        while (true)
        {
            int Counts1 = 0, Counts2 = 0;
            // 取数量 这样就可以整体性的下降
            for (int i = 0; i < Hanglie.GetLength(0); i++)
                if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
                {
                    Counts1++;
                    if (Hanglie[i, 0] - 1 >= 0)
                    {
                        if (ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].CompareTag("Stop") == false)
                            Counts2++;
                        if (ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].transform.GetChildCount() != 0)
                            if (ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].transform.GetChild(0).CompareTag("Stop") == true)
                            {
                                Counts2--;
                            }
                    }
                }

            for (int i = 0; i < Hanglie.GetLength(0); i++)
            {
                if (Hanglie[i, 0] != -1 || Hanglie[i, 1] != -1)
                {
                    GameObject temp1 = ZongFangkuai[Hanglie[i, 0], Hanglie[i, 1]].transform.GetChild(0).gameObject;
                    if (Counts1 == Counts2)
                    {
                        temp1.transform.parent = ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[i, 0] - 1, Hanglie[i, 1]].transform.position;

                        Hanglie[i, 0] -= 1;

                    }
                }
            }
            if (Counts1 != Counts2)
            { break; }
        }
    }

    // 砖块的变形
    void Bianxing()
    {
        if (Qs3 == 1)
        {
            // 什么也不执行        
        }
        else if (Qs3 == 2)
        {
            
            if (Qs3Bianxing == 2)
                Qs3Bianxing = 0;
            // 检测横三格
            if (Qs3Bianxing == 0)
            {
                if(Hanglie[4,1]+1<15 && Hanglie[4,1]-1>=0)
                if (ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] + 1].transform.GetChildCount() == 0 &&
                    ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] - 1].transform.GetChildCount() == 0)
                {
                    GameObject temp1 = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1]].transform.GetChild(0).gameObject;
                    temp1.transform.parent = ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1] -1 ].transform;
                    temp1.transform.position = ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1] -1].transform.position;
                    Hanglie[3, 0] = Hanglie[4, 0];
                    Hanglie[3, 1] = Hanglie[4, 1] -1 ;

                    GameObject temp2 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                    temp2.transform.parent = ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1]+1].transform;
                    temp2.transform.position = ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1]+1].transform.position;
                    Hanglie[5, 0] = Hanglie[4, 0];
                    Hanglie[5, 1] = Hanglie[4, 1] + 1;

                    Qs3Bianxing++;
                }

            }
            else  // 检测竖三格
                if (Qs3Bianxing == 1)
                {
                    if (Hanglie[4, 0] + 1 < 22 && Hanglie[4, 0] - 1 >= 0)
                        if (ZongFangkuai[Hanglie[4, 0]+1, Hanglie[4, 1] ].transform.GetChildCount() == 0 &&
                            ZongFangkuai[Hanglie[4, 0]-1, Hanglie[4, 1]].transform.GetChildCount() == 0)
                        {
                            GameObject temp1 = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1]].transform.GetChild(0).gameObject;
                            temp1.transform.parent = ZongFangkuai[Hanglie[4, 0]+1, Hanglie[4, 1] ].transform;
                            temp1.transform.position = ZongFangkuai[Hanglie[4, 0]+1, Hanglie[4, 1] ].transform.position;
                            Hanglie[3, 0] = Hanglie[4, 0] + 1;
                            Hanglie[3, 1] = Hanglie[4, 1];



                            GameObject temp2 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                            temp2.transform.parent = ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1]].transform;
                            temp2.transform.position = ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1]].transform.position;
                            Hanglie[5, 0] = Hanglie[4, 0] - 1;
                            Hanglie[5, 1] = Hanglie[4, 1];

                            Qs3Bianxing++;
                        }
                }
        }
        else if (Qs3 == 3)
        {
            if (Qs3Bianxing == 2)
                Qs3Bianxing = 0;

            if (Qs3Bianxing == 0)
            {
                if (Hanglie[4, 1] + 1 < 15 && Hanglie[4, 1] - 1 >= 0)
                    if (ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] + 1].transform.GetChildCount() == 0 &&
                        ZongFangkuai[Hanglie[4, 0] + 1, Hanglie[4, 1] - 1].transform.GetChildCount() == 0)
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[0, 0], Hanglie[0, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[4, 0] + 1, Hanglie[4, 1] - 1].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[4, 0] + 1, Hanglie[4, 1] - 1].transform.position;
                        Hanglie[0, 0] = Hanglie[4, 0] + 1;
                        Hanglie[0, 1] = Hanglie[4, 1] - 1;

                        GameObject temp2 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                        temp2.transform.parent = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] + 1].transform;
                        temp2.transform.position = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] + 1].transform.position;
                        Hanglie[5, 0] = Hanglie[4, 0];
                        Hanglie[5, 1] = Hanglie[4, 1] + 1;

                        Qs3Bianxing++;
                    }
            }

            else
                if (Qs3Bianxing == 1)
                {
                    if (Hanglie[4, 1] + 1 < 15 && Hanglie[4, 1] - 1 >= 0)
                    if (ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] - 1].transform.GetChildCount() == 0 &&
                    ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1] - 1].transform.GetChildCount() == 0)
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[0, 0], Hanglie[0, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1] - 1].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1] - 1].transform.position;
                        Hanglie[0, 0] = Hanglie[4, 0] - 1;
                        Hanglie[0, 1] = Hanglie[4, 1] - 1;

                        GameObject temp2 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                        temp2.transform.parent = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] - 1].transform;
                        temp2.transform.position = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] - 1].transform.position;
                        Hanglie[5, 0] = Hanglie[4, 0];
                        Hanglie[5, 1] = Hanglie[4, 1] - 1;

                        Qs3Bianxing++;
                    }
                }
        }
        else if (Qs3 == 4)
        { }
        else if (Qs3 == 5)
        {
            if (Qs3Bianxing == 4)
                Qs3Bianxing = 0;

            if (Qs3Bianxing == 0)
            {
                if (Hanglie[5, 0] + 1 < 22 && Hanglie[5, 1] - 2 >= 0)
                    if (ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] -2].transform.GetChildCount() == 0 &&
                    ZongFangkuai[Hanglie[5, 0] +1, Hanglie[5, 1]].transform.GetChildCount() == 0)
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[5, 0] , Hanglie[5, 1] - 2].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[5, 0] , Hanglie[5, 1] - 2].transform.position;
                        Hanglie[3, 0] = Hanglie[5, 0];
                        Hanglie[3, 1] = Hanglie[5, 1] - 2;

                        GameObject temp2 = ZongFangkuai[Hanglie[2, 0], Hanglie[2, 1]].transform.GetChild(0).gameObject;
                        temp2.transform.parent = ZongFangkuai[Hanglie[5, 0]+1, Hanglie[5, 1]].transform;
                        temp2.transform.position = ZongFangkuai[Hanglie[5, 0]+1, Hanglie[5, 1]].transform.position;
                        Hanglie[2, 0] = Hanglie[5, 0]+1;
                        Hanglie[2, 1] = Hanglie[5, 1];

                        Qs3Bianxing++;
                    }
            }

            else
                if (Qs3Bianxing == 1)
                {
                     if (Hanglie[5, 0] + 2 < 22 && Hanglie[5, 1] + 1 <15)
                    if (ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] + 1].transform.GetChildCount() == 0 &&
                    ZongFangkuai[Hanglie[5, 0] + 2, Hanglie[5, 1]].transform.GetChildCount() == 0)
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] + 1].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] + 1].transform.position;
                        Hanglie[3, 0] = Hanglie[5, 0];
                        Hanglie[3, 1] = Hanglie[5, 1] + 1;

                        GameObject temp2 = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1]].transform.GetChild(0).gameObject;
                        temp2.transform.parent = ZongFangkuai[Hanglie[5, 0] + 2, Hanglie[5, 1]].transform;
                        temp2.transform.position = ZongFangkuai[Hanglie[5, 0] + 2, Hanglie[5, 1]].transform.position;
                        Hanglie[4, 0] = Hanglie[5, 0] + 2;
                        Hanglie[4, 1] = Hanglie[5, 1];

                        Qs3Bianxing++;
                    }
                }
                else
                    if (Qs3Bianxing == 2)
                    {
                        if (Hanglie[5, 0] - 1>=0 && Hanglie[5, 1] + 2 <15)
                        if (ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] + 2].transform.GetChildCount() == 0 &&
                        ZongFangkuai[Hanglie[5, 0] - 1, Hanglie[5, 1]].transform.GetChildCount() == 0)
                        {
                            GameObject temp1 = ZongFangkuai[Hanglie[2, 0], Hanglie[2, 1]].transform.GetChild(0).gameObject;
                            temp1.transform.parent = ZongFangkuai[Hanglie[5, 0] - 1, Hanglie[5, 1]].transform;
                            temp1.transform.position = ZongFangkuai[Hanglie[5, 0] - 1, Hanglie[5, 1]].transform.position;
                            Hanglie[2, 0] = Hanglie[5, 0] - 1;
                            Hanglie[2, 1] = Hanglie[5, 1];

                            GameObject temp2 = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1]].transform.GetChild(0).gameObject;
                            temp2.transform.parent = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] + 2].transform;
                            temp2.transform.position = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] + 2].transform.position;
                            Hanglie[4, 0] = Hanglie[5, 0];
                            Hanglie[4, 1] = Hanglie[5, 1] + 2;

                            Qs3Bianxing++;
                        }
                    }
                    else
                        if (Qs3Bianxing == 3)
                        {
                            if (Hanglie[5, 0] - 2 >=0 && Hanglie[5, 1] - 1 >= 0)
                            if (ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] - 1].transform.GetChildCount() == 0 &&
                            ZongFangkuai[Hanglie[5, 0] - 2, Hanglie[5, 1]].transform.GetChildCount() == 0)
                            {
                                GameObject temp1 = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1]].transform.GetChild(0).gameObject;
                                temp1.transform.parent = ZongFangkuai[Hanglie[5, 0] - 2, Hanglie[5, 1]].transform;
                                temp1.transform.position = ZongFangkuai[Hanglie[5, 0] - 2, Hanglie[5, 1]].transform.position;
                                Hanglie[3, 0] = Hanglie[5, 0] - 2;
                                Hanglie[3, 1] = Hanglie[5, 1];

                                GameObject temp2 = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1]].transform.GetChild(0).gameObject;
                                temp2.transform.parent = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] -1].transform;
                                temp2.transform.position = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1] -1].transform.position;
                                Hanglie[4, 0] = Hanglie[5, 0] ;
                                Hanglie[4, 1] = Hanglie[5, 1] - 1;

                                Qs3Bianxing++;
                            }
                        }
        }
        else if (Qs3 == 6)
        {

            if (Qs3Bianxing == 4)
                Qs3Bianxing = 0;

            if (Qs3Bianxing == 0)
            {
                if (Hanglie[3, 0] + 1 < 22 && Hanglie[3, 1] + 2 < 15)
                    if (ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] + 1].transform.GetChildCount() == 0 &&
                    ZongFangkuai[Hanglie[3, 0] , Hanglie[3, 1] + 2].transform.GetChildCount() == 0&&
                    ZongFangkuai[Hanglie[3, 0] + 1, Hanglie[3, 1]].transform.GetChildCount() == 0)
                    
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[0, 0], Hanglie[0, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[3, 0] + 1, Hanglie[3, 1] ].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[3, 0] + 1, Hanglie[3, 1] ].transform.position;
                        Hanglie[0, 0] = Hanglie[3, 0] + 1;
                        Hanglie[0, 1] = Hanglie[3, 1];

                        GameObject temp2 = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1]].transform.GetChild(0).gameObject;
                        temp2.transform.parent = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] + 1].transform;
                        temp2.transform.position = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] + 1].transform.position;
                        Hanglie[4, 0] = Hanglie[3, 0];
                        Hanglie[4, 1] = Hanglie[3, 1] + 1;

                        GameObject temp3 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                        temp3.transform.parent = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] + 2].transform;
                        temp3.transform.position = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] + 2].transform.position;
                        Hanglie[5, 0] = Hanglie[3, 0];
                        Hanglie[5, 1] = Hanglie[3, 1] + 2;

                        Qs3Bianxing++;
                    }
            }

            else
                if (Qs3Bianxing == 1)
                {
                    if (Hanglie[3, 0] + 2 < 22 && Hanglie[3, 1] - 1 >=0)
                        if (ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] - 1].transform.GetChildCount() == 0 &&
                            ZongFangkuai[Hanglie[3, 0] + 2, Hanglie[3, 1] ].transform.GetChildCount() == 0)
                        {
                            GameObject temp1 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                            temp1.transform.parent = ZongFangkuai[Hanglie[3, 0] + 2, Hanglie[3, 1]].transform;
                            temp1.transform.position = ZongFangkuai[Hanglie[3, 0] +2, Hanglie[3, 1]].transform.position;
                            Hanglie[5, 0] = Hanglie[3, 0] + 2;
                            Hanglie[5, 1] = Hanglie[3, 1];

                            GameObject temp2 = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1]].transform.GetChild(0).gameObject;
                            temp2.transform.parent = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] - 1].transform;
                            temp2.transform.position = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] - 1].transform.position;
                            Hanglie[4, 0] = Hanglie[3, 0];
                            Hanglie[4, 1] = Hanglie[3, 1] - 1;

                            Qs3Bianxing++;
                        }
                }
                else
                    if (Qs3Bianxing == 2)
                    {
                        if (Hanglie[3, 1] - 2 >= 0 && Hanglie[3, 0] - 1 >= 0)
                            if (ZongFangkuai[Hanglie[3, 0] - 1, Hanglie[3, 1] ].transform.GetChildCount() == 0 &&
                                ZongFangkuai[Hanglie[3, 0] , Hanglie[3, 1] -2].transform.GetChildCount() == 0)
                            {
                                GameObject temp1 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                                temp1.transform.parent = ZongFangkuai[Hanglie[3, 0] - 1, Hanglie[3, 1]].transform;
                                temp1.transform.position = ZongFangkuai[Hanglie[3, 0] - 1, Hanglie[3, 1]].transform.position;
                                Hanglie[5, 0] = Hanglie[3, 0] - 1;
                                Hanglie[5, 1] = Hanglie[3, 1];

                                GameObject temp2 = ZongFangkuai[Hanglie[0, 0], Hanglie[0, 1]].transform.GetChild(0).gameObject;
                                temp2.transform.parent = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] - 2].transform;
                                temp2.transform.position = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1] - 2].transform.position;
                                Hanglie[0, 0] = Hanglie[3, 0];
                                Hanglie[0, 1] = Hanglie[3, 1] - 2;

                                Qs3Bianxing++;
                            }
                    }
                    else
                        if (Qs3Bianxing == 3)
                        {
                            if (Hanglie[3, 0] - 2 >= 0 && Hanglie[3, 1] - 1 >= 0)
                                if (ZongFangkuai[Hanglie[3, 0] -1, Hanglie[3, 1] - 1].transform.GetChildCount() == 0 &&
                                    ZongFangkuai[Hanglie[3, 0] - 2, Hanglie[3, 1] -1].transform.GetChildCount() == 0)
                                {
                                    GameObject temp1 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                                    temp1.transform.parent = ZongFangkuai[Hanglie[3, 0] - 1, Hanglie[3, 1] - 1].transform;
                                    temp1.transform.position = ZongFangkuai[Hanglie[3, 0] - 1, Hanglie[3, 1] - 1].transform.position;
                                    Hanglie[5, 0] = Hanglie[3, 0] -1;
                                    Hanglie[5, 1] = Hanglie[3, 1] -1;

                                    GameObject temp2 = ZongFangkuai[Hanglie[0, 0], Hanglie[0, 1]].transform.GetChild(0).gameObject;
                                    temp2.transform.parent = ZongFangkuai[Hanglie[3, 0] - 2, Hanglie[3, 1] - 1].transform;
                                    temp2.transform.position = ZongFangkuai[Hanglie[3, 0] -2, Hanglie[3, 1] - 1].transform.position;
                                    Hanglie[0, 0] = Hanglie[3, 0] - 2;
                                    Hanglie[0, 1] = Hanglie[3, 1] - 1;

                                    Qs3Bianxing++;
                                }
                        }

        }
        else if (Qs3 == 7)
        {
            if (Qs3Bianxing == 4)
                Qs3Bianxing = 0;

            if (Qs3Bianxing == 0)
            {
                if ( Hanglie[4, 1] + 1 < 15)
                    if (ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1] + 1].transform.GetChildCount() == 0 )
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1] + 1].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1] + 1].transform.position;
                        Hanglie[5, 0] = Hanglie[4, 0];
                        Hanglie[5, 1] = Hanglie[4, 1] + 1;

                        GameObject temp2 = ZongFangkuai[Hanglie[1, 0], Hanglie[1, 1]].transform.GetChild(0).gameObject;
                        temp2.transform.parent = ZongFangkuai[Hanglie[4, 0] + 1, Hanglie[4, 1]].transform;
                        temp2.transform.position = ZongFangkuai[Hanglie[4, 0] + 1, Hanglie[4, 1]].transform.position;
                        Hanglie[1, 0] = Hanglie[4, 0] + 1;
                        Hanglie[1, 1] = Hanglie[4, 1];

                        GameObject temp3 = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1]].transform.GetChild(0).gameObject;
                        temp3.transform.parent = ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1] - 1].transform;
                        temp3.transform.position = ZongFangkuai[Hanglie[4, 0] , Hanglie[4, 1] - 1].transform.position;
                        Hanglie[3, 0] = Hanglie[4, 0] ;
                        Hanglie[3, 1] = Hanglie[4, 1] - 1;


                        Qs3Bianxing++;
                    }
            }
            else if (Qs3Bianxing == 1)
            {
                if (Hanglie[4, 0] - 1 >= 0)
                    if (ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1]].transform.GetChildCount() == 0)
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[3, 0], Hanglie[3, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1]].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1]].transform.position;
                        Hanglie[3, 0] = Hanglie[4, 0] - 1;
                        Hanglie[3, 1] = Hanglie[4, 1];


                        Qs3Bianxing++;
                    }
            }
            else if (Qs3Bianxing == 2)
            {
                if (Hanglie[4, 1] - 1 >= 0)
                    if (ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] - 1].transform.GetChildCount() == 0)
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[1, 0], Hanglie[1, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] - 1].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[4, 0], Hanglie[4, 1] - 1].transform.position;
                        Hanglie[1, 0] = Hanglie[4, 0];
                        Hanglie[1, 1] = Hanglie[4, 1] - 1;


                        Qs3Bianxing++;
                    }
            }
            else if (Qs3Bianxing == 3)
            {
                if (Hanglie[4, 0] +1 < 22)
                    if (ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1] ].transform.GetChildCount() == 0)
                    {
                        GameObject temp1 = ZongFangkuai[Hanglie[5, 0], Hanglie[5, 1]].transform.GetChild(0).gameObject;
                        temp1.transform.parent = ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1] ].transform;
                        temp1.transform.position = ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1]].transform.position;
                        Hanglie[5, 0] = Hanglie[4, 0] + 1;
                        Hanglie[5, 1] = Hanglie[4, 1];


                        Qs3Bianxing++;
                    }
            }
 
        }
        else
            if (Qs3 == 8)
            {

                if (Qs3Bianxing == 2)
                    Qs3Bianxing = 0;

                if (Qs3Bianxing == 0)
                {
                    if (Hanglie[4, 1] + 1 < 15 && Hanglie[4, 0] + 1 <22)
                        if (ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1] ].transform.GetChildCount() == 0 &&
                            ZongFangkuai[Hanglie[4, 0] + 1, Hanglie[4, 1] + 1].transform.GetChildCount() == 0)
                        {
                            GameObject temp1 = ZongFangkuai[Hanglie[2, 0], Hanglie[2, 1]].transform.GetChild(0).gameObject;
                            temp1.transform.parent = ZongFangkuai[Hanglie[4, 0] + 1, Hanglie[4, 1] + 1].transform;
                            temp1.transform.position = ZongFangkuai[Hanglie[4, 0] + 1, Hanglie[4, 1] + 1].transform.position;
                            Hanglie[2, 0] = Hanglie[4, 0] + 1;
                            Hanglie[2, 1] = Hanglie[4, 1] + 1;

                            GameObject temp2 = ZongFangkuai[Hanglie[1, 0], Hanglie[1, 1]].transform.GetChild(0).gameObject;
                            temp2.transform.parent = ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1] ].transform;
                            temp2.transform.position = ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1] ].transform.position;
                            Hanglie[1, 0] = Hanglie[4, 0] +1;
                            Hanglie[1, 1] = Hanglie[4, 1];

                            Qs3Bianxing++;
                        }
                }

                else
                    if (Qs3Bianxing == 1)
                    { 
                        if (Hanglie[4, 0] -1 >=0 )
                            if (ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1] - 1].transform.GetChildCount() == 0 &&
                            ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1]].transform.GetChildCount() == 0)
                            {
                                GameObject temp1 = ZongFangkuai[Hanglie[2, 0], Hanglie[2, 1]].transform.GetChild(0).gameObject;
                                temp1.transform.parent = ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1]].transform;
                                temp1.transform.position = ZongFangkuai[Hanglie[4, 0] - 1, Hanglie[4, 1] ].transform.position;
                                Hanglie[2, 0] = Hanglie[4, 0] - 1;
                                Hanglie[2, 1] = Hanglie[4, 1];

                                GameObject temp2 = ZongFangkuai[Hanglie[1, 0], Hanglie[1, 1]].transform.GetChild(0).gameObject;
                                temp2.transform.parent = ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1] - 1].transform;
                                temp2.transform.position = ZongFangkuai[Hanglie[4, 0] +1, Hanglie[4, 1] - 1].transform.position;
                                Hanglie[1, 0] = Hanglie[4, 0] +1;
                                Hanglie[1, 1] = Hanglie[4, 1] - 1;

                                Qs3Bianxing++;
                            }
                    }
 
            }
    }
    
    // 砖块消行 
    void Xiaohang()
    {
        int Counts2 = 0,temp=0;
        int[] Counts1 = new int[] { -1,-1,-1,-1 };
        bool AK = false;

        // 检测消行
        for (int i = 0; i < ZongFangkuai.GetLength(0); i++)
        {
            Counts2 = 0;

            for (int j = 0; j < ZongFangkuai.GetLength(1); j++)
            {
                if (ZongFangkuai[i, j].transform.GetChildCount() == 1)
                {
                    Counts2++;
                }
            }
            if (Counts2 == ZongFangkuai.GetLength(1))
            {
                Counts1[temp++] = i;
            }
        }

        // 开始消行
        for (int k = 0; k < temp; k++)
        {
            for (int i = 0; i < ZongFangkuai.GetLength(1); i++)
            {

                 Destroy (ZongFangkuai[Counts1[k], i].transform.GetChild(0).gameObject);
                 FirstXK = false;
                 FirthXK = true;
            }

            FKXH++;
            FKXH1 = Counts1[temp - 1];

           
 
        }

        if (temp != 0)
        {
            GametextNum += temp;
            GameText.text = "得分is: " + GametextNum;
        }



    }

    // 砖块消行后上方砖块下降处理
    void FKXiajiang()
    {

        // 开始下降
            for (int i = 1; i < ZongFangkuai.GetLength(0); i++)
            {
                for (int j = 0; j < ZongFangkuai.GetLength(1); j++)
                {
                    if (ZongFangkuai[i, j].transform.GetChildCount() == 1)
                    {
                        GameObject temp1 = ZongFangkuai[i, j].transform.GetChild(0).gameObject;
                        if (temp1.tag.CompareTo("Stop") == 0 && i>=FKXH1)
                        {

                             temp1.transform.parent = ZongFangkuai[i-FKXH, j].transform;
                             temp1.transform.position = ZongFangkuai[i-FKXH, j].transform.position;

                        }
                    }
                }
            }
            FirstXK = true;
            FirthXK = false;
            FKXH = 0;
            FKXH1 = 0;

    }
}